<?php
/**
 * 数据大小过滤器
 */

namespace app\service\RpcService\Helper;

use Hprose\Filter;
use stdClass;
use think\facade\Log;

class SizeFilter implements Filter
{
    private $message;

    public function __construct($message)
    {
        $this->message = $message;
    }

    public function inputFilter($data, stdClass $context)
    {
        Log::write($this->message . ' 输入 input size: ' . (strlen($data) / 1024) . 'Kb');
        return $data;
    }

    public function outputFilter($data, stdClass $context)
    {
        Log::write($this->message . ' 输出 size: ' . (strlen($data) / 1024) . 'Kb');
        return $data;
    }
}
